package me.keiwu.admin.util;

import me.keiwu.admin.domain.AbstractBaseEntity;
import me.keiwu.admin.domain.system.SysUser;

import java.util.Date;

/**
 * Created by kei on 02/11/2017.
 */
public class EntityUtil {

    public static boolean setModifiedBy(AbstractBaseEntity entity) {
        return setModifiedBy(entity, false);
    }

    public static boolean setModifiedBy(AbstractBaseEntity entity, boolean isCreate) {
        SysUser loginUser = UserUtil.getLoginUser();
        if (loginUser == null) return false;
        entity.setLastModifiedBy(loginUser.getUsername());
        entity.setLastModifiedDate(new Date());
        if (isCreate) {
            entity.setCreatedBy(loginUser.getUsername());
            entity.setCreatedDate(new Date());
        }
        return true;
    }
}
